import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/ui/custom/real_rich_text.dart';

///************************
/// @auther nb
/// @function 支付订单
/// @创建日期 2019/8/2 16:25
///************************
class OrderPayment extends StatefulWidget {
  @override
  _OrderPaymentState createState() => _OrderPaymentState();
}

class _OrderPaymentState extends State<OrderPayment> {
  TextEditingController controller=TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      resizeToAvoidBottomPadding: false,
      appBar: UiUtils.appBar(context, "支付订单"),
      body: Column(
        children: <Widget>[
          UiUtils.dividerWidget(ScreenUtil().setWidth(20)),
          getContent(),
          getBottom(),
        ],
      ),
    );
  }

  getContent() {
    return Expanded(
      flex: 1,
      child: EasyRefresh(
          child: ListView(
            children: <Widget>[
              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
                child: Text(
                  "支付",
                  style: TextStyles.custom(
                      28, Colours.appC1, Font.PingFangBlod),
                ),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
                child: RealRichText([
                  TextSpan(
                      text: "应支付金额：",
                      style: TextStyles.custom(
                          24, Colours.appC2, Font.PingFangMedium)),
                  TextSpan(
                      text: "298.00元",
                      style: TextStyles.custom(
                          28, Color(0xFFC81623), Font.PingFangMedium))
                ]),
              ),
              Container(
                decoration: BoxDecoration(
                  color: Color(0xFFffdedf),
                  borderRadius: BorderRadius.circular(5),
                ),
                padding: EdgeInsets.fromLTRB(
                    ScreenUtil().setWidth(20),
                    ScreenUtil().setWidth(10),
                    ScreenUtil().setWidth(20),
                    ScreenUtil().setWidth(10)),
                margin: EdgeInsets.fromLTRB(
                    ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(34)),
                child: Text(
                  "如果无特别提示说明，应支付金额与平台要求不一致，请联系平台客服，切勿直接联系商家并且提及平台，礼遇等字样，违禁者直接封号处理；请勿通过淘宝客下单，勿使用花呗，信用卡付款",
                  style: TextStyles.custom(
                      24, Color(0xFFe1251b), Font.PingFangMedium),
                ),
              ),
              UiUtils.dividerWidget(ScreenUtil().setWidth(20)),
              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
                child: Text(
                  "支付核对",
                  style: TextStyles.custom(
                      28, Colours.appC1, Font.PingFangBlod),
                ),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
                child: Row(
                  children: <Widget>[
                    Container(
                      child: Text("请输入订单号：", style: getTextStyle()),
                    ),
                    Expanded(
                      flex: 1,
                      child: GestureDetector(
                        onTap: () {},
                        child: Container(
                          alignment: Alignment.centerRight,
                          child: Text(
                            "如何查找订单号？",
                            style: TextStyles.custom(24, Color(0xFF508cff),
                                Font.PingFangMedium),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
                height: ScreenUtil().setWidth(60),
                decoration: BoxDecoration(
                    border: Border.all(
                        color: Color(0xFFe5e5e5), width: ScreenUtil().setWidth(1)),
                    borderRadius: BorderRadius.circular(5)),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      flex: 1,
                      child: Container(
                        alignment: Alignment.center,
                        child: TextField(

                          style: TextStyles.custom(24, Colours.appC2, Font.PingFangMedium),
                          controller: controller,
                          decoration: InputDecoration(
                            border: InputBorder.none,
                            contentPadding: EdgeInsets.all(0)
                          ),
                        ),
                      ),
                    ),
                   GestureDetector(
                     onTap: (){getClipboardContents();},
                     child:  Container(
                       decoration: BoxDecoration(
                           color: Color(0xFFe3393c),
                           borderRadius:
                           BorderRadius.horizontal(right: Radius.circular(5))),
                       alignment: Alignment.center,
                       height: ScreenUtil().setWidth(60),
                       width: ScreenUtil().setWidth(230),
                       child: Text(
                         "粘贴",
                         style: TextStyles.custom(
                             24, Colors.white, Font.PingFangMedium),
                       ),
                     ),
                   )
                  ],
                ),
              ),

              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(48), ScreenUtil().setWidth(30), 0),
                child:   Container(
                  child: Text("请输入实际支付金额：", style: getTextStyle()),
                ),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                    ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
                height: ScreenUtil().setWidth(60),
                decoration: BoxDecoration(
                    border: Border.all(
                        color: Color(0xFFe5e5e5), width: ScreenUtil().setWidth(1)),
                    borderRadius: BorderRadius.circular(5)),
                child: TextField(
                  style: TextStyles.custom(24, Colours.appC2, Font.PingFangMedium),
                  decoration: InputDecoration(
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.all(0)
                  ),
                ),
              ),
            ],
          )),
    );
  }

  getBottom() {
    return Container(
      width: ScreenUtil().setWidth(690),
      height: ScreenUtil().setWidth(88),
      alignment: Alignment.center,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(22),
        color: Color(0xFFdf3033),
      ),
      margin: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(20),
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(30)),
      child: Text(
        "下一步",
        style:
            TextStyles.custom(28, Colors.white, Font.PingFangMedium),
      ),
    );
  }

  getTextStyle() {
    return TextStyles.custom(
        24, Color(0xFF666666), Font.PingFangMedium);
  }

  getClipboardContents() async {
    ///1.使用异步调用获取返回值
    var clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
    if (clipboardData != null) {
      ///调用Flutter的State重新赋值加载界面
      this.setState(() {
        ///将异步获取到的文本数据赋值到全局字符串对象上，我这里是将粘贴板上面的内容赋值到TextField元素的TextEditingController控制器上
        controller.text = clipboardData.text;
      });
    }

    ///2.开始核对
  }
}
